package org.example.mppg.test.crud;

import jakarta.annotation.Resource;
import org.example.mppg.MpPgApplication;
import org.example.mppg.domain.entity.Student;
import org.example.mppg.logic.service.IStudentService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import static org.slf4j.LoggerFactory.getLogger;

/**
 * @Package: org.example.mppg.test.crud;
 * @ClassName: Demo.java
 * @Description:
 * @author: bo
 * @date: 2024/10/13 15:13
 */

@RunWith(SpringRunner.class)
@SpringBootTest(classes = MpPgApplication.class)
public class Demo {

    private static final Logger log = getLogger(Demo.class);

    @Resource
    private IStudentService studentServices;

    @Test
    public void testCRUD() {
        Student stu = new Student();
        stu.setStuName("张三");
        stu.setGradeNo(1);
        stu.setClassNo(1);

        studentServices.getBaseMapper().insert(stu);
        Long id = stu.getId();

        Student inserted = studentServices.getById(id);
        log.info("after insert: {}", inserted);

        stu.setStuName("张三新");
        studentServices.getBaseMapper().updateById(stu);
        Student stuUpdated = studentServices.getById(id);
        log.info("after update: {}", stuUpdated);

        studentServices.getBaseMapper().deleteById(stu);
        Student stuDeleted = studentServices.getById(id);
        log.info("after delete: {}", stuDeleted);
    }

    @Test
    public void truncate() {
        studentServices.truncate();
    }
}